//
//  ZYWelcomeViewController.swift
//  CZ29WeiboZYH
//
//  Created by 沐颜澈 on 16/6/26.
//  Copyright © 2016年 muyanche. All rights reserved.
//

import UIKit
import SDWebImage


class ZYWelcomeViewController: UIViewController {
    
    override func loadView() {

        view = backImageView
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.headImgeView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                    
                }, completion: { (_) -> Void in
                    
                    //---------------6.27-------------------------
                    //当前的动画完成了之后,改变根控制器
                    //发送通知给Appdelegate改变根控制器
                    NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVCNoti, object:
                        "o,welcome")
                    
                
                })
        }
    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    
    //设置UI
    private func setupUI() {
        //添加控件
        view.addSubview(headImgeView)
        view.addSubview(welcomeLabel)
        view.addSubview(welcomeLabel)
        
        //设置约束
        headImgeView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
            
        }
        
        //设置label的约束
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImgeView.snp_bottom).offset(17)
        }
    }
    
    
    //MARK: - 懒加载控件
    //
    private lazy var backImageView: UIImageView = UIImageView(imagName: "ad_background")
    //设置图像
    private lazy var headImgeView: UIImageView = {
       let img = UIImageView(imagName: "avatar_default_big")
        //设置layer
        img.layer.cornerRadius = 45
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.borderWidth = 3
        img.layer.masksToBounds = true
        
        //设置图片
        img.sd_setImageWithURL(NSURL(string: ZYUserAccountTools.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "picture1"))
            
        
        return img
    
    }()
    
    //欢迎回来的标签
    private lazy var welcomeLabel: UILabel = {
        
        let label = UILabel()
        label.text = "欢迎回朋友圈"
        label.font = UIFont.systemFontOfSize(28)
        label.textAlignment = .Center
        label.textColor = UIColor.blueColor()
        label.alpha = 0
        return label
    
    }()
    

}
